<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 500px;
            height: 500px;
            background-color: #f00;
        }

        .a {
            width: 300px;
            height: 300px;
            background-color: #ff0;
        }

        .a1 {
            width: 100px;
            height: 100px;
            background-color: #000;
        }
    </style>
</head>

<body>

    <div class="box">
        <div class="a">
            <div class="a1"></div>
        </div>
    </div>

    <script>


        // 阻止事件冒泡
        //    不希望事件向外传播  --- 只触发自身的事件 ， 不要触发父元素的事件


        var oBox = document.querySelector('.box');
        var oA = document.querySelector('.a');
        var oA1 = document.querySelector('.a1');

        oBox.addEventListener('click', function () {
            console.log(1);
        })
        oA.addEventListener('click', function () {
            console.log(2);
        })

        oA1.addEventListener('click', function (e) {
            // 主流浏览器阻止事件冒泡
            // stopPropagation 阻止事件冒泡
            // e.stopPropagation();

            // IE8阻止事件冒泡
            // e.cancelBubble = true ;
            if (e.stopPropagation) {
                e.stopPropagation();
            } else {
                e.cancelBubble = true;
            }
            console.log(3);
        })


    </script>

</body>

</html>